import random

def get_random_key(dictionary):
    keys = list(dictionary.keys())
    random_key = random.choice(keys)
    return random_key

def get100(z ,i):
    num = round(z / i, 2)
    percentage = num * 100
    # 将百分比转换为字符串并添加百分号后缀
    result = "{:.2f}%".format(percentage)
    return result

if __name__ == '__main__':
    i = 0
    z = 0
    binary = {'A': 10, 'B': 11, 'C': 12,'D':13,'E':14,'F':15}
    #binary = {  'D': 13, 'E': 14}
    while True:
        key = get_random_key(binary)
        print('16进制数：' + key)
        user_input = input("请输入16进制数对应的10进制数：")
        i = i + 1
        if user_input == str(binary[key]):
            z = z + 1
            b = get100(z, i)
            print(f"回答正确 回答{i}次 正确率{b}\n")
        else:
            b = get100(z, i)
            print(f"回答错误 答案是:{binary[key]}\n 回答{i}次 正确率{b}")
